//获取应用实例
var app = getApp();
var FormCheckRule = {

    idCardRule1: /^[0-9]{14}([0-9]|X|x)$/,
    idCardRule2: /^[0-9]{17}([0-9]|X|x)$/,
    nameRule: /^[\u4e00-\u9fa5]{2,12}$/,
    telRule:/^[1]{1}[0-9]{10}$/,
    verifyCodeRule:/^[a-zA-Z0-9]{1,6}$/,
    carNbrSufRule: /^[a-zA-Z0-9]{4}[a-zA-Z0-9\u4E00-\u9FA5]{1,2}$/,
    carCodeRule: /^[a-zA-Z0-9]{6}$/,
    sendVerifyCodeSuccess:"验证码发送成功！",
    carCodeNullMessage:"请输入车身架号后6位",
    carCodeErrorMessage:"请输入车身架号后6位",
    carNbrSufNullMessage:"请输入车牌号码",
    carNbrSufErrorMessage:"请输正确的车牌号码",
    cardNbrNullMessage:"请输入身份证号！",
    cardNbrErrorMessage:"请输入正确的身份证号！",

    cardNameNullMessage:"请输入车主姓名！",
    cardNameErrorMessage:"请输入正确的车主姓名！",

    telephoneNullMessage:"请输入手机号码！",
    telephoneErrorMessage:"请输入正确的手机号码！",

    verifyCodeNullMessage:"请输入验证码！",
    cardPictureNullMessage:"请上传手持身份证照片！",
    policyPictureNullMessage:"请上传交强险保单副本！",


    cellNumNullMessage:"请输入收件人电话！",
    cellNumErrorMessage:"请输入正确的收件人电话！",
    contactNameNullMessage:"请输入收件人姓名！",
    contactNameErrorMessage:"请输入正确的收件人姓名！",
    areaNameNullMessage:"请选择所在地区！",
    streetNullMessage:"请输入详细地址！",
    num:0

};


Page({
    data: {
        area:"请选择所在地区",
        areaStyle:"color: #B2B2B2;font-size:34rpx",
        errorFocusName:"",
        num:0,
        items:['A','B','C','D','E','F','G','H','J','K','L','M','N','P','Q','R','S','T','U','V','W','X','Y'],
        carNumPrefix:"粤A",
        handleImage:"https://yzres.oss-cn-shenzhen.aliyuncs.com/apptest/images/bizType/img_nj_2@3x.png",
        conditions:"1、车辆注册日期在2013-10-13~2017-10-13之间的车辆。\n2、无未处理的交通违法。\n3、限定5座（包含5座）以下的蓝牌车。\n4、有效期内的交强险。\n",
        doc:"1、检验标志申请表（邮政速递人员上门揽收时提供）；\n2、行驶证正副本原件；\n3、交强险副本原件；\n4、车船税发票原件或免税证明原件（如交强险附带车船税购买的，只收交强险副本原件）\n",
        verifyCodeText:"获取验证码",
        cardPicture:"",
        policyPicture:"",
        isNoticeShow:false,
        isAdvertShow:false,
        advertIconUrl:"",
        needInvoice:0,
        agree:0,
        isShowFootNav:true,
        isCanScroll:true,
        isShowSupplementaryData:false//是否展示粤S
    },
    onShareAppMessage: function () {   //分享功能
        return {
            title: '车辆年检',
            desc: '车辆年检',
            path: '/pages/handle/handle'
        }
    },
    //底部切换页面方法
    toUrlTap:function (e) {
        var url = e.currentTarget.dataset.url;
        if(url!='/pages/handle/handle'){
            if(url == ''){
                //develop（开发版），trial（体验版），release（正式版）
                var res = {
                    appid:app.globalData.appid,
                    path: app.globalData.path,
                    envVersion: app.globalData.envVersion
                }
                app.crossToUrl(res)
            }else {
                app.redirectTo({url: url});
            }
        }
    },
    onLoad: function () {
        var pageObj = this;

        var advertOpt = {   //请求广告
            url: app.globalData.host + "/wx/an/ad.ajax",
            data: {},
            sucFn: function (result) {
                if(result.body!=null) {
                    pageObj.setData({
                        isAdvertShow: true,
                        advertIconUrl: result.body.icon
                    });
                }
            }
        };
        app.ajax(advertOpt);

        app.initAddress();
        if(app.globalData.openId!=''&&app.globalData.openId!=null&&app.globalData.openId!='null'){
            var opt2 = {
                url: app.globalData.host+"/wx/an/list.ajax",
                data: {
                    'bizFlag':app.globalData.bizDoingFlag,
                    'orderType':app.globalData.orderType
                },
                sucFn:function (result) {
                    var num = "";
                    if(result.body.orderList.length!=0){
                        num = result.body.orderList.length;
                    }
                    pageObj.setData({
                        "num": num
                    });
                }
            };
            app.ajax(opt2);
        }else{
            wx.login({//调用登录接口
                success: function (res) {
                    var opt = {//后台兑换openId
                        url: app.globalData.host + "/wx/an/eo.ajax",
                        data: {
                            'code': res.code
                        },
                        showLoadFlag:"false",
                        sucFn: function (result) {
                            if(result.body.openId!=''&&result.body.openId!=null&&result.body.openId!='null'){
                                app.globalData.openId = result.body.openId;
                                var opt2 = {
                                    url: app.globalData.host+"/wx/an/list.ajax",
                                    data: {
                                        'bizFlag':app.globalData.bizDoingFlag,
                                        'orderType':app.globalData.orderType
                                    },
                                    showLoadFlag:"false",
                                    sucFn:function (result) {
                                        var num = 0;
                                        if(result.body.orderList.length!=0){
                                            num = result.body.orderList.length;
                                        }
                                        pageObj.setData({
                                            "num": num
                                        });
                                    }
                                };
                                app.ajax(opt2);
                            }else{
                                app.toastAuthFailModal();
                                return false;
                            }
                        }
                    };
                    app.ajax(opt);
                }
            });
        }


        var page =  app.getStorageSync(app.globalData.cachePageKey);
        if(page!=null&&page!=""){
            this.setData({
                "carNumPrefix":page.carNumPrefix,
                "carNumberSuffix":page.carNumberSuffix,
                "carCode":page.carCode,
                "agree":page.agree
            });
            this.initCondition();

            if(page.carNumberSuffix!=''&&page.carNumberSuffix!=null) {
                if (FormCheckRule.carNbrSufRule.test(page.carNumberSuffix)) {
                    this.setData({"carNumberSuffixIconType": "success"});
                } else if (page.carNumberSuffix.length > 0) {
                    this.setData({"carNumberSuffixIconType": "error"});
                } else {
                    this.setData({"carNumberSuffixIconType": ""});
                }
            }
            if(page.carCode!=''&&page.carCode!=null) {
                if (FormCheckRule.carCodeRule.test(page.carCode)) {
                    this.setData({"carCodeIconType": "success"});
                } else if (page.carCodeRule.length > 0) {
                    this.setData({"carCodeIconType": "error"});
                } else {
                    this.setData({"carCodeIconType": ""});
                }
            }
            //粤S
            if(app.isYueS(page.carNumPrefix)){
                this.setData({
                    "cardName":page.cardName,
                    "cardNum":page.cardNum,
                    "telephone":page.telephone,
                    "agree":page.agree
                });
                this.setData({isShowSupplementaryData: true});

                if(page.cardName!=''&&page.cardName!=null) {
                    if (FormCheckRule.nameRule.test(page.cardName)) {
                        this.setData({"cardNameIconType": "success"});
                    } else if (page.cardName.length > 0) {
                        this.setData({"cardNameIconType": "error"});
                    } else {
                        this.setData({"cardNameIconType": ""});
                    }
                }

                if(page.cardNum!=''&&page.cardNum!=null){
                    if( FormCheckRule.idCardRule1.test(page.cardNum)&& page.cardNum.length == 15 ) {
                        this.setData({"cardNumIconType": "success"});
                    } else if (FormCheckRule.idCardRule2.test(page.cardNum)&&page.cardNum.length == 18) {
                        this.setData({"cardNumIconType": "success"});
                    } else if(page.cardNum.length>0){
                        this.setData({"cardNumIconType": "error"});
                    }else{
                        this.setData({"cardNumIconType": ""});
                    }
                }

                if(page.telephone!=''&&page.telephone!=null) {
                    if (FormCheckRule.telRule.test(page.telephone)) {
                        this.setData({"telephoneIconType": "success"});
                    } else if (page.telephone.length > 0) {
                        this.setData({"telephoneIconType": "error"});
                    } else {
                        this.setData({"telephoneIconType": ""});
                    }
                }
            }


            if(page.address!=null){
                this.setData({
                    "area":page.area,
                    "areaStyle":"",
                    "address.street":page.address.street,
                    "address.provinceId":page.address.provinceId,
                    "address.cityId":page.address.cityId,
                    "address.countyId":page.address.countyId,
                    "address.provinceName":page.address.provinceName,
                    "address.cityName":page.address.cityName,
                    "address.countyName":page.address.countyName,
                    "address.cellNum":page.address.cellNum,
                    "address.contactName":page.address.contactName
                });
                if(page.address.contactName!=''&&page.address.contactName!=null) {
                    if (FormCheckRule.nameRule.test(page.address.contactName)) {
                        this.setData({"contactNameIconType": "success"});
                    } else if (page.address.contactName.length > 0) {
                        this.setData({"contactNameIconType": "error"});
                    } else {
                        this.setData({"contactNameIconType": ""});
                    }
                }

                if(page.address.cellNum!=''&&page.address.cellNum!=null) {
                    if (FormCheckRule.telRule.test(page.address.cellNum)) {
                        this.setData({"cellNumIconType": "success"});
                    } else if (page.address.cellNum.length > 0) {
                        this.setData({"cellNumIconType": "error"});
                    } else {
                        this.setData({"cellNumIconType": ""});
                    }
                }
                if(page.area=='请选择所在地区'){
                    this.setData({areaStyle: "color: #B2B2B2;font-size:34rpx"});
                }else{
                    this.setData({areaStyle: "color:#1a1a1a;font-size:34rpx"});
                }
                if(page.certPlaceName==''){
                    this.setData({certPlaceStyle: "color: #B2B2B2;font-size:34rpx"});
                }else{
                    this.setData({certPlaceStyle: "color:#1a1a1a;font-size:34rpx",certPlaceText:page.certPlaceName});
                }
            }
        }

    },
    initCondition : function(){
        var pageObj = this;
        var carNumber = this.data.carNumPrefix ;
        var opt = {
            url: app.globalData.host + "/wx/an/c.ajax",
            data: {carNumber:carNumber},
            sucFn: function (result) {
                pageObj.setData({
                    conditions: result.body.conditionArray.join("\n"),
                    doc: result.body.docArray.join("\n")
                });
            }
        };
        app.ajax(opt)
    },
    onHide:function () {
        app.setStorageSync(app.globalData.cachePageKey,this.data);
    },
    onShow:function () {
       var page = app.getStorageSync(app.globalData.cachePageKey);
        var cardPicture = app.getStorageSync(app.globalData.cardPictureKey)||'';
        var policyPicture = app.getStorageSync(app.globalData.policyPictureKey)||'';
        this.setData({
            cardPicture: cardPicture==''?page.cardPicture:cardPicture,
            policyPicture: policyPicture==''?page.policyPicture:policyPicture,
            num: page.num
        });
        app.setStorageSync(app.globalData.cardPictureKey, null);
        app.setStorageSync(app.globalData.policyPictureKey, null);

        if( page.carNumPrefix==null){
            this.setData({carNumPrefix:"粤A"});
            this.setData({isShowSupplementaryData: false});
            this.initCondition();
        }
        if( page.carNumberSuffix==null){
            this.setData({carNumberSuffix:null,carNumberSuffixIconType: ""});
        }
        if( page.carCode==null){
            this.setData({carCode:null,carCodeIconType: ""});
        }

        if( page.cardName==null){
            this.setData({cardName:null,cardNameIconType: ""});
        }
        if( page.cardNum==null){
            this.setData({cardNum:null,cardNumIconType: ""});
        }
        if( page.telephone==null){
            this.setData({telephone:null,telephoneType: ""});
        }
        if(page.verifyCodeClear=='1'){
            this.setData({verifyCode:null});
        }
    },
    //点击车牌前缀
    carNumPrefixTap: function(e){
        this.setData({
            carNumPrefixShowView: true,
            isShowFootNav:false
        })
    },
    //确定车牌前缀
    confirmCarNumPrefixTap:function(e){
        var isShowSupplementaryData = app.isYueS(e.target.dataset.name);
        this.setData({
            isShowSupplementaryData:isShowSupplementaryData,
            carNumPrefix: e.target.dataset.name,
            carNumPrefixShowView: false,
            isShowFootNav: true
        })
        this.initCondition();
    },
    //确定车牌前缀蒙层
    confirmCarNumPrefixViewTap:function(e){
        this.setData({
            carNumPrefixShowView: false,
            isShowFootNav: true
        })
    },
    //取消
    cancelCarPrefixTap:function(e){
        this.setData({
            carNumPrefixShowView: false,
            isShowFootNav: true
        })
    },
    mineTap:function (e) {
        app.setStorageSync(app.globalData.cachePageKey,this.data);
        var url = e.currentTarget.dataset.url;
        app.redirectTo({url: url});
    },
    verifyCodeTap:function (e) {
        var pageObj = this;
        var telephone = pageObj.data.telephone;
        var btnText = pageObj.data.verifyCodeText;
        if(btnText != "获取验证码"&& btnText != "重新发送"){
            return false;
        }
        if(telephone==''){
            app.errorToast(FormCheckRule.telephoneNullMessage);
            return false
        }else if(!FormCheckRule.telRule.test(telephone)){
            app.errorToast(FormCheckRule.telephoneErrorMessage);
            return false;
        }
        var opt = {   //请求广告
            url: app.globalData.host + "/wx/an/vc.ajax",
            data: {phoneNumber:telephone},
            sucFn: function (result) {
                if(result.body!=null) {
                    app.errorToast(FormCheckRule.sendVerifyCodeSuccess);
                    if (btnText === "获取验证码" || btnText === "重新发送") {
                        btnText = '59秒后获取';    //第一次59秒
                        var second = 59; //用来记录秒
                        var SEND = setInterval(function () {
                            second--;
                            btnText =  second + '秒后获取'; //显示时间
                            pageObj.setData({
                                verifyCodeText: btnText
                            });
                            if (second == 0) {
                                btnText = "重新发送";
                                clearInterval(SEND);
                                pageObj.setData({
                                    verifyCodeText: btnText
                                });
                            } //到过60秒时停止
                        }, 1000); //每1000毫秒即1秒执行一次此函数
                    }
                }
            }
        };
        app.ajax(opt);
    },
    infoInput:function (e) {
        var id = e.currentTarget.id;
        var value = e.detail.value.replace(/(^\s*)|(\s*$)/g,"");
        if(id=="carNumberSuffix"){
            this.setData({"carNumberSuffix": value});
            if( value =='') {
                this.setData({"carNumberSuffixIconType": "success"});
            } else if( FormCheckRule.carNbrSufRule.test(value)) {
                this.setData({"carNumberSuffixIconType": "success"});
            } else if(value.length>0){
                this.setData({"carNumberSuffixIconType": "error"});
            }else{
                this.setData({"carNumberSuffixIconType": ""});
            }

        }else if(id=="carCode"){
            this.setData({"carCode": value});
            if( value =='') {
                this.setData({"carCodeIconType": "success"});
            } else if( FormCheckRule.carCodeRule.test(value)) {
                this.setData({"carCodeIconType": "success"});
            } else if(value.length>0){
                this.setData({"carCodeIconType": "error"});
            }else{
                this.setData({"carCodeIconType": ""});
            }

        }else if(id=="cardName"){
            this.setData({"cardName": value});
            if( value =='') {
                this.setData({"cardNameIconType": "success"});
            } else if( FormCheckRule.nameRule.test(value)) {
                this.setData({"cardNameIconType": "success"});
            } else if(value.length>0){
                this.setData({"cardNameIconType": "error"});
            }else{
                this.setData({"cardNameIconType": ""});
            }
        }else if(id=="cardNum"){
            value = value.substr(0, 18);
            this.setData({"cardNum": value});
            if( value =='') {
                this.setData({"cardNumIconType": "success"});
            } else if( value.length == 15 && FormCheckRule.idCardRule1.test(value)) {
                this.setData({"cardNumIconType": "success"});
            } else if (value.length == 18 && FormCheckRule.idCardRule2.test(value)) {
                this.setData({"cardNumIconType": "success"});
            } else if(value.length>0){
                this.setData({"cardNumIconType": "error"});
            }else{
                this.setData({"cardNumIconType": ""});
            }

        }else if(id=="telephone"){
            value = value.substr(0, 11);
            this.setData({"telephone": value});
            if( value =='') {
                this.setData({"telephoneIconType": "success"});
            }else if( FormCheckRule.telRule.test(value)) {
                this.setData({"telephoneIconType": "success"});
            } else if(value.length>0){
                this.setData({"telephoneIconType": "error"});
            }else{
                this.setData({"telephoneIconType": ""});
            }
        }else if(id=="address.contactName"){
            this.setData({"address.contactName": value});
            if( value =='') {
                this.setData({"contactNameIconType": "success"});
            } else if(value.length>0&&FormCheckRule.nameRule.test(value)) {
                this.setData({"contactNameIconType": "success"});
            } else if(value.length>0){
                this.setData({"contactNameIconType": "error"});
            }else{
                this.setData({"contactNameIconType": ""});
            }
        }else if(id=="address.cellNum"){
            value = value.substr(0, 11);
            this.setData({"address.cellNum": value});
            if( value =='') {
                this.setData({"cellNumIconType": "success"});
            } else if(FormCheckRule.telRule.test(value)) {
                this.setData({"cellNumIconType": "success"});
            } else if(value.length>0){
                this.setData({"cellNumIconType": "error"});
            }else{
                this.setData({"cellNumIconType": ""});
            }
        }else if(id=="address.street"){
            this.setData({"address.street": value});
            if( value =='') {
                this.setData({"streetIconType": "success"});
            } else if(value.length>=5) {
                this.setData({"streetIconType": "success"});
            }else if(value!=''&&value!=null&&value.length<5){
                this.setData({"streetIconType": "error"});
            }else{
                this.setData({"streetIconType": ""});
            }
        }
    },
    carNumberSuffixBlur:function (e) {
        var value = e.detail.value;
        if(value!=null&&value!=''){
            this.setData({carNumberSuffix: value.toUpperCase()});
        }
    },
    carCodeBlur:function (e) {
        var value = e.detail.value;
        if(value!=null&&value!=''){
            this.setData({carCode: value.toUpperCase()});
        }
    },
    cardNumBlur:function (e) {
        var value = e.detail.value;
        if(value!=null&&value!=''){
            this.setData({cardNum: value.toUpperCase()});
        }
    },
    formSubmit:function (e) {
        var pageObj = this;
        var formData = e.detail.value;
        var carNumberSuffix = formData.carNumberSuffix;
        var carNumPrefix = formData.carNumPrefix;
        var carNumber = formData.carNumber;
        var carCode = formData.carCode;

        var cardNum = formData.cardNum;
        var cardName = formData.cardName;
        var telephone = formData.telephone;
        var verifyCode = formData.verifyCode;
        var cardPicture = formData.cardPicture;
        var policyPicture = formData.policyPicture;

        var cellNum = formData['address.cellNum'];
        var contactName = formData['address.contactName'];
        var street = formData['address.street'];
        var provinceId = formData['address.provinceId'];
        var isYueS = app.isYueS(carNumPrefix);
        var contactNameErrorScrollIntoViewName = isYueS?'policyPictureView':'carCodeView';

        var flag = app.check([
            {
                value: carNumberSuffix,
                errorFocusName:"carNumberSuffix",
                errorScrollIntoViewName:"handleView",
                fn: function (value) {
                    if(''==value){
                        app.errorToast(FormCheckRule.carNbrSufNullMessage);
                        return false;
                    }else if(FormCheckRule.carNbrSufRule.test(value)){
                        return true;
                    }else{
                        app.errorToast(FormCheckRule.carNbrSufErrorMessage);
                        return false;
                    }
                }
            },
            {
                value: carCode,
                errorFocusName:"carCode",
                errorScrollIntoViewName:"handleView",
                fn: function (value) {
                    if(''==value){
                        app.errorToast(FormCheckRule.carCodeNullMessage);
                        return false;
                    }else if(FormCheckRule.carCodeRule.test(value)){
                        return true;
                    }else{
                        app.errorToast(FormCheckRule.carCodeErrorMessage);
                        return false;
                    }
                }
            },
            {
                value: cardName,
                errorFocusName:"cardName",
                errorScrollIntoViewName:"carCodeView",
                fn: function (value) {
                    if(isYueS){
                        if(''==value){
                            app.errorToast(FormCheckRule.cardNameNullMessage);
                            return false;
                        }else if(FormCheckRule.nameRule.test(value)){
                            return true;
                        }else{
                            app.errorToast(FormCheckRule.cardNameErrorMessage);
                            return false;
                        }
                    }else{
                        return true;
                    }

                }
            },
            //粤s才出发的条件
            {
                value: cardName,
                errorFocusName:"cardName",
                errorScrollIntoViewName:"carCodeView",
                fn: function (value) {
                    if(isYueS){
                        if(''==value){
                            app.errorToast(FormCheckRule.cardNameNullMessage);
                            return false;
                        } else if (FormCheckRule.nameRule.test(value)) {
                            return true;
                        } else{
                            app.errorToast(FormCheckRule.cardNameErrorMessage);
                            return false;
                        }
                    }else{
                        return true;
                    }

                }
            },
            {
                value: cardNum,
                errorFocusName:"cardNum",
                errorScrollIntoViewName:"cardNameView",
                fn: function (value) {
                    if(isYueS){
                        if(''==value){
                            app.errorToast(FormCheckRule.cardNbrNullMessage);
                            return false;
                        }else if( value.length == 15 && FormCheckRule.idCardRule1.test(value)) {
                            return true;
                        } else if (value.length == 18 && FormCheckRule.idCardRule2.test(value)) {
                            return true;
                        } else{
                            app.errorToast(FormCheckRule.cardNbrErrorMessage);
                            return false;
                        }
                    }else{
                        return true;
                    }

                }
            },
            {
                value: telephone,
                errorFocusName:"telephone",
                errorScrollIntoViewName:"cardNameView",
                fn: function (value) {
                    if(isYueS){
                        if(''==value){
                            app.errorToast(FormCheckRule.telephoneNullMessage);
                            return false;
                        }else if (FormCheckRule.telRule.test(value)) {
                            return true;
                        } else{
                            app.errorToast(FormCheckRule.telephoneErrorMessage);
                            return false;
                        }
                    }else{
                        return true;
                    }

                }
            },
            {
                value: telephone,
                errorFocusName:"telephone",
                errorScrollIntoViewName:"cardNameView",
                fn: function (value) {
                    if(isYueS){
                        if(''==value){
                            app.errorToast(FormCheckRule.telephoneNullMessage);
                            return false;
                        }else if (FormCheckRule.telRule.test(value)) {
                            return true;
                        } else{
                            app.errorToast(FormCheckRule.telephoneErrorMessage);
                            return false;
                        }
                    }else{
                        return true;
                    }
                }
            },
            {
                value: verifyCode,
                errorFocusName:"verifyCode",
                errorScrollIntoViewName:"telephoneView",
                fn: function (value) {
                    if(isYueS) {
                        if ('' == value) {
                            app.errorToast(FormCheckRule.verifyCodeNullMessage);
                            return false;
                        } else {
                            return true;
                        }
                    }else{
                        return true;
                    }
                }
            },
            {
                value: cardPicture,
                errorFocusName:"cardPicture",
                errorScrollIntoViewName:"verifyCodeView",
                fn: function (value) {
                    if(isYueS) {
                        if ('' == value) {
                            app.errorToast(FormCheckRule.cardPictureNullMessage);
                            return false;
                        } else {
                            return true;
                        }
                    }else{
                        return true;
                    }
                }
            },
            {
                value: policyPicture,
                errorFocusName:"policyPicture",
                errorScrollIntoViewName:"cardPictureView",
                fn: function (value) {
                    if(isYueS) {
                        if ('' == value) {
                            app.errorToast(FormCheckRule.policyPictureNullMessage);
                            return false;
                        } else {
                            return true;
                        }
                    }else{
                        return true;
                    }
                }
            },
            //地址
            {
                value: contactName,
                errorFocusName:"contactName",
                errorScrollIntoViewName:contactNameErrorScrollIntoViewName,
                fn: function (value) {
                    if(''==value){
                        app.errorToast(FormCheckRule.contactNameNullMessage);
                        return false;
                    }else if(FormCheckRule.nameRule.test(value)){
                        return true;
                    }else{
                        app.errorToast(FormCheckRule.contactNameErrorMessage);
                        return false;
                    }
                }
            },
            {
                value: cellNum,
                errorFocusName:"cellNum",
                errorScrollIntoViewName:"contactNameView",
                fn: function (value) {
                    if(''==value){
                        app.errorToast(FormCheckRule.cellNumErrorMessage);
                        return false;
                    }else if(FormCheckRule.telRule.test(value)){
                        return true;
                    }else{
                        app.errorToast(FormCheckRule.cellNumErrorMessage);
                        return false;
                    }
                }
            },
            {
                value: provinceId,
                errorFocusName:"provinceId",
                errorScrollIntoViewName:"cellNumView",
                rule: app.globalData.Rule.required,
                fn: function (value) {
                    if(value!=''){
                        return true;
                    }else{
                        app.errorToast(FormCheckRule.areaNameNullMessage);
                        return false
                    }
                }
            },
            {
                value: street,
                errorFocusName:"street",
                errorScrollIntoViewName:"areaView",
                rule: app.globalData.Rule.required,
                fn: function (value) {
                    if(value.length>=5){
                        return true;
                    }else{
                        app.errorToast(FormCheckRule.streetNullMessage);
                        return false
                    }
                }
            }
        ]);
        if (!flag) {
            return false;
        }
        // if(this.data.agree==0){
        //     app.errorToast("请阅读并同意《新车六年免检服务协议》!");
        //     return false;
        // }
        if(app.globalData.openId==''||app.globalData.openId==null||app.globalData.openId=='null'){
            app.toastAuthFailModal();
            return false;
        }
        var param = formData;
        param['address.fullAddr'] = formData['address.provinceName']+formData['address.cityName']+formData['address.countyName']+street;
        var opt = {
            url: app.globalData.host+"/wx/an/handling.ajax",
            data: param,
            sucFn:function (result) {
                param['serviceFee'] = result.body.serviceFee;
                param['doc'] = pageObj.data.doc;
                param['serviceFeeDesc'] = result.body.serviceFeeDesc;
                param['totalChargeFee'] = result.body.totalChargeFee;
                param['totalFee'] = result.body.totalFee;
                app.setStorageSync(app.globalData.cacheOrderResKey, param);
                if(result.body.hasViolation==0){//0/没有 1/有 2/未知
                    app.navigateTo({url:'../payment/payment'});
                }else if(result.body.hasViolation==1){// 1 有违章
                    var opt = {
                        title: "温馨提示",
                        content: "系统检测到您的车"+param.carNumber+"有未办理违章，请处理完违章再办理年检",
                        cancelText: "确定",
                        confirmText: "去办年检",
                        success: function () {
                            app.navigateTo({url:'../payment/payment'});
                        },
                        cancel: function () {
                            console.log("确定");
                        }
                    };
                    app.showModal(opt);
                }else if(result.body.hasViolation==2){//2 未知
                    var opt = {
                        title: "温馨提示",
                        content: "系统检测不到您的车"+param.carNumber+"的违章情况，请确认您的车无违章后再办理年检",
                        cancelText: "确定",
                        confirmText: "去办年检",
                        success: function () {
                            app.navigateTo({url:'../payment/payment'});
                        },
                        cancel: function () {
                            console.log("确定");
                        }
                    };
                    app.showModal(opt);
                }else if(result.body.hasViolation==3){//3 年检未到期
                    var opt = {
                        title: "暂不需要年检",
                        content: "系统检测到"+param.carNumber+"检验有效期至："+result.body.endTime,
                        cancelText: "确定",
                        confirmText: "去办年检",
                        success: function () {
                            app.navigateTo({url:'../payment/payment'});
                        },
                        cancel: function () {
                            console.log("确定");
                        }
                    };
                    app.showModal(opt);
                }
            }
        };
        app.ajax(opt);
    },
    agreeTap:function (e) {
        this.setData({
            isNoticeShow:true,
            isShowFootNav:false
        });
    },
    uploadTap:function (e) {
        var type = e.currentTarget.dataset.type;
        var value = e.currentTarget.dataset.value;
        app.navigateTo({
            url: '../handle/upload/upload?type='+type+'&uploadImgSrc='+value
        });
    },
    checkTap:function (e) {
        var agree = e.target.dataset.agree;
        if(agree==0){
            agree = 1;
        }else{
            agree = 0;
        }
        this.setData({agree: agree});
    },
    noticeKnowTap:function (e) {
        this.setData({
            isNoticeShow:false,
            isShowFootNav:true
        });
    },
    areaTap:function (e) {
        this.setData({
            isAddressShow: true,
            isShowFootNav:false
        });
    },
    addressShowTap:function (e) {
        this.setData({
            isAddressShow: false,
            isShowFootNav:true
        });
    },
    bindAddressChange: function (e) {
        app.bindAddressChange(e);
    },
    confirmAddressTap:function (e) {
        var current_value = this.data.value;
        var provinceName = this.data.proviceData[current_value[0]].name;
        var cityName = this.data.cityData[current_value[1]].name;
        var countyName = "";
        if(this.data.districtData[current_value[2]].name!=null){
            countyName = this.data.districtData[current_value[2]].name;
        }
        this.setData({
            isShowFootNav:true,
            isAddressShow: false,
            areaStyle:"color:#1a1a1a;font-size:34rpx",
            area:provinceName+cityName+countyName,
            "address.provinceId":this.data.proviceData[current_value[0]].id,
            "address.cityId":this.data.cityData[current_value[1]].id,
            "address.countyId":this.data.districtData[current_value[2]].id,
            "address.provinceName":provinceName,
            "address.cityName":cityName,
            "address.countyName":countyName
        });
    },
    cancelAddressTap:function (e) {
        this.setData({
            isShowFootNav:true,
            isAddressShow: false
        });
    }
});
